//整屏效果
(function($){
    var ch=0,cw=0,divW=0,divH=0;
    function setScreen(options){
         var  h=options&&options.h?options.h:0;
        ch=$(window).height()-h;
        cw=$(window).width();
        if(options&&options._this)options._this.css({width:cw,height:ch});
        divW=cw;
        divH=ch;
    }
    function setBgImg(options){
        var imgH=options.height||1080,
            imgW=options.width||1920;
      if(divH==0||divW==0) setScreen()
      var img=options._this;
        if(divH/divW>imgH/imgW){
            img.height(divH);
            img.width(divH/(imgH/imgW));
        }else{
            img.width(divW);
            img.height(divW*(imgH/imgW));

        }
        var newW=img.width();
        var newH=img.height();
        img.css({'left':-(newW-divW)/2,'top':-(newH-divH)/2});
    };
    function setContent(div){
        div.css({width:divW,height:divH});
    };
    $.fn.extend({
        fitMain:function(optioin){
          optioin=optioin||{};
          optioin._this=$(this);
          setScreen(optioin)
            $(window).resize(function(){
                setScreen(setScreen(optioin));
            })
        },
        fitDiv:function(){
            var $this=$(this);
            setContent($this);
            $(window).resize(function(){
                setContent($this);
            })
        },
        fitBgImg:function(option){
           var options=option||{};
          options._this=$(this);
            setBgImg(options);
            $(window).resize(function(){
                setBgImg(options);
            })
        }
    });
})(jQuery);

